package com.sqly.doc.ble.xty;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListPopupWindow;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.cazaea.sweetalert.SweetAlertDialog;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.tnb.tnb;
import com.sqly.doc.util.MyApplication;
import com.vivachek.nova.bleproxy.BleProxy;
import com.vivachek.nova.bleproxy.annotation.BleGlucoseDataType;
import com.vivachek.nova.bleproxy.annotation.BleMeasureToastType;
import com.vivachek.nova.bleproxy.entity.BaseBluetooth;
import com.vivachek.nova.bleproxy.entity.GKIEntity;
import com.vivachek.nova.bleproxy.entity.GKIHistoryEntity;
import com.vivachek.nova.bleproxy.entity.ValueEntity;
import com.vivachek.nova.bleproxy.util.DateTimeUtils;
import com.sqly.doc.adapter.ControlAdapter;
import com.sqly.doc.base.BaseHolder;
import com.sqly.doc.base.BaseRecyclerViewAdapter;
import com.sqly.doc.util.DeviceUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ControlActivity extends MyBaseActivity {
	private static final String TAG = "ControlActivity";

	public static final String DEVICE = "device";
	private ListPopupWindow mPopupWindow;
	private ControlAdapter mControlAdapter;
	private List<String> mCommands;
	private BaseBluetooth mBluetoothDevice;
	private CheckBox mCbAutoConnect;
	private RadioGroup mRg;

	private boolean mIsShowConcentration = false;
	private List<String> mResponse = new ArrayList<>();
	private List<String> mOriginData = new ArrayList<>();

	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
		}
	};
	private int mReConnect = 0;
	private RecyclerView mRv;
	private BaseRecyclerViewAdapter<String> mAdapter;
	private boolean mIsRealTime = false;
	private String mUnit;
	LinearLayout back;
	private TextView  title,uname,deviceVal;
	private Button xtcdqd;

	@Override
	protected void initUI( ) {
		setContentView(R.layout.activity_control);
		mBluetoothDevice = (BaseBluetooth) getIntent().getSerializableExtra(DEVICE);
		if (mBluetoothDevice == null) {
			finish();
			return;
		}
		mRv = findViewById(R.id.rv);
		title = (TextView) findViewById(R.id.title);
		title.setText("血糖值测量");
		uname = (TextView) findViewById(R.id.uname);
		uname.setText("设置");
		xtcdqd = (Button)findViewById(R.id.xtcdqd);
		xtcdqd.setVisibility(View.GONE);
		deviceVal = ((TextView) findViewById(R.id.deviceVal));
		deviceVal.setVisibility(View.GONE);
		deviceVal.setText("4.6");
		xtcdqd.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				new SweetAlertDialog(ControlActivity.this, SweetAlertDialog.ERROR_TYPE)
						.setTitleText("提示")
						.setContentText("本次测定结果为"+deviceVal.getText().toString()+"，确定选择本次测定结果吗?")
						.setConfirmText("确定")
						.setCancelText("取消")
						.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
							@Override
							public void onClick(SweetAlertDialog sweetAlertDialog) {
								sweetAlertDialog.dismiss();
								Intent intent = new Intent(ControlActivity.this, tnb.class);
								Bundle b = new Bundle();
								b.putString("deviceVal", deviceVal.getText().toString());
								intent.putExtras(b);
								setResult(0, intent);
								finish();
							}
						})
						.show();
			}
		});
		uname.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View v) {
				sendCommand(4);
			}
		});
		back = (LinearLayout) findViewById(R.id.back);

		mCbAutoConnect = findViewById(R.id.cbAutoConnect);
		((TextView) findViewById(R.id.tvDeviceName)).setText(
				String.format(getString(R.string.device_name),
						TextUtils.isEmpty(mBluetoothDevice.getDevice().getName()) ? "" :
								mBluetoothDevice.getDevice().getName()));

		((TextView) findViewById(R.id.tvDeviceMac)).setText(
				String.format(getString(R.string.device_mac),
						TextUtils.isEmpty(mBluetoothDevice.getDevice().getAddress()) ? "" :
								mBluetoothDevice.getDevice().getAddress()));

		((TextView) findViewById(R.id.tvDeviceSn)).setText(
				String.format(getString(R.string.device_sn),
						TextUtils.isEmpty(mBluetoothDevice.getSn()) ? "" : mBluetoothDevice.getSn()));
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		mRg = findViewById(R.id.rg);
		mRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				showData();
			}
		});
		initPop();
		findViewById(R.id.tvRight).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mPopupWindow.show();
			}
		});
		mRv.setAdapter(initAdapter());
		mRg.check(R.id.rbResponse);
	}

	@Override
	protected void initData() {

	}

	@Override
	protected void initListener() {

	}

	private BaseRecyclerViewAdapter<String> initAdapter() {
		mAdapter = new BaseRecyclerViewAdapter<String>(R.layout.item_content) {
			@Override
			protected void convert(BaseHolder holder, String s) {
				holder.setText(R.id.tvContent, s);
			}
		};
		return mAdapter;
	}

	private void showData() {
		int id = mRg.getCheckedRadioButtonId();
		if (id == R.id.rbOriginData) {
			mAdapter.clearData();
			mAdapter.addAll(mOriginData);
		} else {
			mAdapter.clearData();
			mAdapter.addAll(mResponse);
		}
		mAdapter.notifyDataSetChanged();
		mRv.scrollToPosition(mAdapter.getItemCount() - 1);
	}

	private void initPop() {
		String[] commands = getResources().getStringArray(R.array.command);
		mCommands = Arrays.asList(commands);
		mPopupWindow = new ListPopupWindow(ControlActivity.this);
		mControlAdapter = new ControlAdapter(ControlActivity.this, mCommands);
		mPopupWindow.setAdapter(mControlAdapter);
		mPopupWindow.setWidth(DeviceUtil.getScreenWidth(MyApplication.getApp()) - 140);
		mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
		mPopupWindow.setModal(true);
		mPopupWindow.setAnchorView(findViewById(R.id.tvRight));
		mPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Log.i("commond_i","========="+position);
				sendCommand(position);
				mPopupWindow.dismiss();
			}
		});
	}

	private void sendCommand(int position) {
		switch (position) {
			case 0:
				// sn
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendSn(mBluetoothDevice);
				break;
			case 1:
				// unit

				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendUnit(mBluetoothDevice);
				break;
			case 2:
				// set time
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendSetTime(mBluetoothDevice);
				break;
			case 3:
				// read time
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendReadDeviceTime(mBluetoothDevice);
				break;
			case 4:
				// real time send sn、unit、set time
				clearData();
				mIsRealTime = true;
				BleProxy.getInstance().sendSn(mBluetoothDevice);
				break;
			case 5:
				// get N history
				InputNumDialog dialog = new InputNumDialog();
				dialog.setOnDialogClickListener(new InputNumDialog.OnDialogClickListener() {
					@Override
					public void onCancel() {

					}

					@Override
					public void onConfirm(int num) {
						mIsRealTime = false;
						clearData();
						BleProxy.getInstance().sendTakeNHistory(mBluetoothDevice, num);
					}
				});
				dialog.show(getSupportFragmentManager(), TAG);
				break;
			case 6:
				// get all history
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendExportHistory(mBluetoothDevice);
				break;
			case 7:
				// delete recent data
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendDeleteRecentRecord(mBluetoothDevice);
				break;
			case 8:
				// delete all data
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendDeleteHistory(mBluetoothDevice);
				break;
			case 9:
				// read device version
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendDeviceVersion(mBluetoothDevice);
				break;
			case 10:
				// TODO: 2019-08-05 读取血糖浓度
				mIsRealTime = false;
				clearData();
				BleProxy.getInstance().sendReadGlucoseConcentration(mBluetoothDevice);
				break;
			case 11:
				// TODO: 2019-08-03 设置血糖浓度
				if (TextUtils.isEmpty(mUnit)) {
					mIsRealTime =false;
					mIsShowConcentration = true;
					clearData();
					BleProxy.getInstance().sendUnit(mBluetoothDevice);
					return;
				}
				GlucoseConcentrationDialog concentrationDialog = new GlucoseConcentrationDialog();
				concentrationDialog.setOnDialogClickListener(new GlucoseConcentrationDialog.OnDialogClickListener() {
					@Override
					public void onCancel() {

					}

					@Override
					public void onConfirm(int[] low, int[] high) {
						mIsRealTime = false;
						clearData();
						BleProxy.getInstance().sendSetGlucoseConcentration(mBluetoothDevice, low, high);
					}
				});
				concentrationDialog.show(getSupportFragmentManager(), TAG);
				break;
			case 12:
				mIsRealTime = false;
				clearData();
				// get gki history
				BleProxy.getInstance().sendGetGKIByHistory(mBluetoothDevice);
				break;
		}

	}

	private void clearData() {
		mOriginData.clear();
		mResponse.clear();
	}

	@Override
	public void openNotifySuccess(BaseBluetooth bleDevice) {
		super.openNotifySuccess(bleDevice);
		mResponse.add(getString(R.string.ble_open_notify_success));
		showData();
	}

	@SuppressLint("StringFormatMatches")
	@Override
	public void responseRealTimeGlucose(BaseBluetooth device, ValueEntity glucoseEntity) {
		super.responseRealTimeGlucose(device, glucoseEntity);
		mIsRealTime = false;
		String date = DateTimeUtils.getStringByFormat(glucoseEntity.getMeasureTime(),
				DateTimeUtils.dateFormatYMDHM);
		String glucose = String.format(getString(R.string.glucose), date, glucoseEntity.getValue(),
				glucoseEntity.getUnit());
		deviceVal.setText(""+glucoseEntity.getValue());
		xtcdqd.setVisibility(View.VISIBLE);
		Log.i("responseRealTimeGlucose","=========="+glucose);
		mResponse.add(glucose);
		showData();
	}

	@Override
	public void responseRealTimeKetone(BaseBluetooth device, ValueEntity glucoseEntity) {
		super.responseRealTimeKetone(device, glucoseEntity);
		mIsRealTime = false;
		String date = DateTimeUtils.getStringByFormat(glucoseEntity.getMeasureTime(),
				DateTimeUtils.dateFormatYMDHM);
		String glucose = String.format(getString(R.string.ketone), date, glucoseEntity.getValue(),
				glucoseEntity.getUnit());
		mResponse.add(glucose);
		showData();
	}

	@Override
	public void responseUnit(BaseBluetooth device, String unit) {
		super.responseUnit(device, unit);
		mUnit = unit;
		String responseSn = String.format(getString(R.string.device_unit), unit);
		mResponse.add(responseSn);
		showData();
		if (mIsRealTime) {
			BleProxy.getInstance().sendSetTime(mBluetoothDevice);
		}
		if (mIsShowConcentration) {
			sendCommand(11);
		}
	}

	@Override
	public void responseSn(BaseBluetooth device, String sn) {
		super.responseSn(device, sn);
		String responseSn = String.format(getString(R.string.device_sn), sn);
		mResponse.add(responseSn);
		showData();
		if (mIsRealTime) {
			BleProxy.getInstance().sendUnit(device);
		}
	}

	@Override
	public void responseSetTimeSuccess(BaseBluetooth device) {
		super.responseSetTimeSuccess(device);

		String responseSetTime = getString(R.string.set_ble_time_success);
		mResponse.add(responseSetTime);
		showData();

	}

	@Override
	public void onConnectSuccess(final BaseBluetooth bleDevice) {
		super.onConnectSuccess(bleDevice);
		mResponse.add(getString(R.string.device_connect_success));
		showData();
		mHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				BleProxy.getInstance().notify(bleDevice);
			}
		}, mReConnect * 1000);
		mReConnect = 0;
	}

	@Override
	public void responseRealTimeToast(BaseBluetooth device, int toastType) {
		super.responseRealTimeToast(device, toastType);
		switch (toastType) {
			case BleMeasureToastType.LAST_TIME_MEASURE:
				mResponse.add(getString(R.string.ble_toast_last_time_measure_text));
				break;
			case BleMeasureToastType.INSERTED_TEST_STRIP:
				mResponse.add(getString(R.string.ble_toast_inserted_test_strip_text));
				break;

			case BleMeasureToastType.WAITING_COLLECTION_BLOOD:
				mResponse.add(getString(R.string.ble_toast_waiting_collection_blood_text));
				break;

			case BleMeasureToastType.FINISH_COLLECTION_BLOOD:
				mResponse.add(getString(R.string.ble_toast_finish_collection_blood_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_DEFAULT:
				mResponse.add(getString(R.string.ble_toast_measure_error_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_APPLICATION_OF_SAMPLE:
				mResponse.add(getString(R.string.ble_toast_please_replace_the_new_test_strip_and_retest_it_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_USED_OR_CONTAMINATED_TESTSTRIP:
				mResponse.add(getString(R.string.ble_toast_the_test_strip_has_been_used_please_replace_the_new_test_strip_and_retest_it_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_DAMAGED_OR_MISMATCHED_TESTSTRIP:
				mResponse.add(getString(R.string.ble_toast_please_replace_the_matching_new_test_strip_and_retest_it_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_SAMPLE:
				mResponse.add(getString(R.string.ble_toast_please_replace_the_new_test_strip_and_retest_it_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_TEMPERATURE_BEYOND_RANGE:
				mResponse.add(getString(R.string.ble_toast_please_move_to_the_appropriate_temperature_environment_and_wait_20_minutes_to_retest_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_SOFTWARE:
				mResponse.add(getString(R.string.ble_toast_please_retest_if_equipment_is_abnormal_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_HARDWARE:
				mResponse.add(getString(R.string.ble_toast_please_retest_if_equipment_is_abnormal_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_INSERT_TESTSTRIP_WHEN_CHARGING:
				mResponse.add(getString(R.string.ble_toast_please_unplug_the_charging_line_of_the_blood_glucose_meter_reboot_it_and_conduct_blood_glucose_test_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_INSUFFICIENT_SAMPLE_SIZE:
				mResponse.add(getString(R.string.ble_toast_please_replace_the_new_test_strip_and_retest_it_to_ensure_adequate_sample_addition_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_MEASURE_RESULT_HIGHER_THAN_SYSTEM_DETECTION_RANGE:
				mResponse.add(getString(R.string.ble_toast_the_test_result_is_too_high_please_retest_it_text));
				break;

			case BleMeasureToastType.MEASURE_ERROR_MEASURE_RESULT_LOWER_THAN_SYSTEM_DETECTION_RANGE:
				mResponse.add(getString(R.string.ble_toast_the_test_result_is_too_low_please_retest_it_text));
				break;
		}
		showData();
	}

	@Override
	public void responseHistory(BaseBluetooth device, List<ValueEntity> historyGlucose) {
		super.responseHistory(device, historyGlucose);
		mResponse.add(String.format(getString(R.string.ble_history_count), historyGlucose.size()));
		for (ValueEntity valueEntity : historyGlucose) {
			String data = "";
			if (valueEntity.getType() == BleGlucoseDataType.GLUCOSE_BLOOD) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				data = String.format(getString(R.string.glucose), date, valueEntity.getValue(),
						valueEntity.getUnit());
			} else if (valueEntity.getType() == BleGlucoseDataType.GLUCOSE_BLOOD_BY_GKI) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				data = String.format(getString(R.string.glucose_by_gki), date,
						valueEntity.getValue(),
						valueEntity.getUnit());
			} else if (valueEntity.getType() == BleGlucoseDataType.GLUCOSE_CTRL) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				data = String.format(getString(R.string.glucose_by_ctrl), date,
						valueEntity.getValue(),
						valueEntity.getUnit());
			} else if (valueEntity.getType() == BleGlucoseDataType.BLOOD_KETONE) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				data = String.format(getString(R.string.ketone), date, valueEntity.getValue(),
						valueEntity.getUnit());
			} else if (valueEntity.getType() == BleGlucoseDataType.BLOOD_KETONE_BY_GKI) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				data = String.format(getString(R.string.ketone_by_gki), date,
						valueEntity.getValue(),
						valueEntity.getUnit());
			} else if (valueEntity.getType() == BleGlucoseDataType.KETONE_CTRL) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				data = String.format(getString(R.string.ketone_by_ctrl), date,
						valueEntity.getValue(),
						valueEntity.getUnit());
			} else if (valueEntity.getType() == BleGlucoseDataType.GKI) {
				String date = DateTimeUtils.getStringByFormat(valueEntity.getMeasureTime(),
						DateTimeUtils.dateFormatYMDHM);
				GKIEntity gki = (GKIEntity) valueEntity;
				data = String.format(getString(R.string.gki), date,
						gki.getGlucose().getValue(),
						gki.getGlucose().getUnit(), gki.getKetone().getValue(),
						gki.getKetone().getUnit(), gki.getValue());
			}
			mResponse.add(data);
		}
		showData();
	}

	@Override
	public void onDisconnect(String mac, boolean isActiveDisConnected) {
		super.onDisconnect(mac, isActiveDisConnected);
		if (!isActiveDisConnected) {
			mResponse.add(getString(R.string.ble_disconnect));
		}
		if (mCbAutoConnect.isChecked()) {
			if (!isActiveDisConnected) {
				BleProxy.getInstance().connect(mac);
			}
			showData();
		} else {
			finish();
		}
	}

	@Override
	public void onBleDeviceClose() {
		super.onBleDeviceClose();
		mResponse.add(getString(R.string.device_disconnect));
		if (mCbAutoConnect.isChecked()) {
			BleProxy.getInstance().connect(mBluetoothDevice.getDevice().getAddress());
			showData();
		} else {
			finish();
		}

	}

	@Override
	public void onConnectFail(String mac) {
		super.onConnectFail(mac);
		if (mCbAutoConnect.isChecked()) {
			BleProxy.getInstance().destroy();
			mReConnect++;
			mResponse.add(String.format(getString(R.string.device_reconnect), mReConnect));
			mHandler.postDelayed(new Runnable() {
				@Override
				public void run() {
					BleProxy.getInstance().connect(mBluetoothDevice.getDevice().getAddress());
				}
			}, mReConnect * 1000);
		} else {
			mResponse.add(getString(R.string.device_connect_fail));
		}
		showData();
	}

	@Override
	public void openNotifyFail() {
		super.openNotifyFail();
		if (mCbAutoConnect.isChecked()) {
			BleProxy.getInstance().destroy();
			mReConnect++;
			mResponse.add(getString(R.string.ble_open_notify_fail_reconnect));
			mResponse.add(String.format(getString(R.string.device_reconnect), mReConnect));
			mHandler.postDelayed(new Runnable() {
				@Override
				public void run() {
					BleProxy.getInstance().connect(mBluetoothDevice.getDevice().getAddress());
				}
			}, mReConnect * 1000);
		} else {
			mResponse.add(getString(R.string.ble_open_notify_fail));
		}
		showData();
	}


	@Override
	public void responseOriginData(BaseBluetooth device, String originData, boolean isReceiver) {
		super.responseOriginData(device, originData, isReceiver);
		if (isReceiver) {
			mOriginData.add(String.format(getString(R.string.ble_receiver_data), originData));
		} else {
			mOriginData.add(String.format(getString(R.string.ble_send_data), originData));
		}
		showData();

	}

	@Override
	public void responseDeviceVersion(BaseBluetooth device, String version) {
		super.responseDeviceVersion(device, version);
		mResponse.add(String.format(getString(R.string.device_version), version));
		showData();
	}

	@Override
	public void responseReadTime(BaseBluetooth convertBleDevice, long deviceTime) {
		super.responseReadTime(convertBleDevice, deviceTime);
		mResponse.add(String.format(getString(R.string.device_time), DateTimeUtils.getStringByFormat(deviceTime, DateTimeUtils.dateFormatYMDHM)));
		showData();
	}

	@Override
	public void responseGKI(BaseBluetooth device, ValueEntity glucoseEntity) {
		super.responseGKI(device, glucoseEntity);
		mIsRealTime = false;
		GKIEntity gki = (GKIEntity) glucoseEntity;
		mResponse.add(String.format(getString(R.string.gki), DateTimeUtils.getStringByFormat(gki
						.getMeasureTime(), DateTimeUtils.dateFormatYMDHM), gki.getGlucose().getValue(),
				gki.getKetone().getUnit(), gki.getKetone().getValue(), gki.getKetone().getUnit(),
				gki.getValue()));
	}

	@Override
	public void responseGKIHistory(BaseBluetooth device, List<ValueEntity> result) {
		super.responseGKIHistory(device, result);
		mResponse.add(String.format(getString(R.string.ble_history_count), result.size()));
		for (ValueEntity entity : result) {
			GKIHistoryEntity e = (GKIHistoryEntity) entity;
			mResponse.add(String.format(getString(R.string.gki), DateTimeUtils.getStringByFormat(e
							.getMeasureTime(), DateTimeUtils.dateFormatYMDHM), e.getGlucose().getValue(),
					e.getGlucose().getUnit(), e.getKetone().getValue(), e.getKetone().getUnit(),
					e.getValue()));
		}
	}

	@Override
	public void onBleGKIMode(BaseBluetooth device, boolean isOpen) {
		super.onBleGKIMode(device, isOpen);
		mResponse.add(String.format(getString(R.string.ble_gki_mode), isOpen ?
				getString(R.string.open) : getString(R.string.close)));
		showData();
	}

	@Override
	public void onDeleteHistorySuccess() {
		super.onDeleteHistorySuccess();
		mResponse.add(getString(R.string.delete_all_history_success));
		showData();
	}

	@Override
	public void onDeleteRecentDataSuccess() {
		super.onDeleteRecentDataSuccess();
		mResponse.add(getString(R.string.delete_recent_data_success));
		showData();
	}

	@Override
	public void responseReadGlucoseConcentration(BaseBluetooth convertBleDevice, float low,
                                                 float high, String unit) {
		super.responseReadGlucoseConcentration(convertBleDevice, low, high, unit);
		mResponse.add(String.format(getString(R.string.device_glucose_concentration), low, unit,
				high, unit));
		showData();
	}

	@Override
	public void responseSetGlucoseConcentrationSuccess(BaseBluetooth convertBleDevice) {
		super.responseSetGlucoseConcentrationSuccess(convertBleDevice);
		mResponse.add(getString(R.string.ble_set_glucose_concentration_success));
		showData();
	}

	@Override
	protected void onDestroy() {
		clearData();
		BleProxy.getInstance().destroy();
		super.onDestroy();
	}

	@Override
	public void onPointerCaptureChanged(boolean hasCapture) {

	}
}
